import { BaseModel, ModelAttributes, WhereCondition, OrderBy, PaginationOptions } from './BaseModel';

export interface CharacterAttributes {
  id?: number;
  name: string;
  avatar_url?: string;
  description?: string;
  personality?: string;
  background_story?: string;
  greeting_message?: string;
  is_active?: boolean;
  created_at?: Date;
  updated_at?: Date;
}

export class Character extends BaseModel {
  constructor() {
    super('ai_character');
  }

  
  /**
   * 分页获取角色列表
   * @param pagination 分页选项
   * @param where 查询条件
   * @param orderBy 排序条件
   */
  async getCharactersWithPagination(
    pagination: PaginationOptions,
    where: WhereCondition = {},
    orderBy?: OrderBy[]
  ): Promise<{ data: CharacterAttributes[]; total: number; page: number; limit: number; totalPages: number }> {
    // 默认只查询激活的角色
    if (!where.hasOwnProperty('is_active')) {
      where.is_active = true;
    }
    
    // 默认按创建时间倒序排列
    if (!orderBy) {
      orderBy = [{ field: 'created_at', direction: 'DESC' }];
    }
  
    return await this.findWithPagination(where, pagination, '*', orderBy);
  }
}